/////////////////////////////////////////////////////////////////////////////////////
// Include Files

// ????
#include "Rendering\GLExt.h"
//#include "GLee\GLee.h"

#include "Systems\Scene.h"
#include "Objects\Object.h"
#include "Systems\Window.h"

/////////////////////////////////////////////////////////////////////////////////////
// ISingleton<CScene> Static Initialization
CScene *ISingleton<CScene>::m_pInstance = CE_NULL;

/////////////////////////////////////////////////////////////////////////////////////
// CScene Implementation

void CScene::Initialize()
{
	// start the process at 60 frames per second
	StartProcess(60);
}

void CScene::Shutdown()
{
	// stop the process
	StopProcess();
}

void CScene::AddObject( ABCObject *_pObject )
{
	m_Mutex.Lock();
	m_lstObjects.Append(_pObject);
	m_Mutex.Unlock();
}

void CScene::ProcessBegin()
{
}

void CScene::ProcessEnd()
{
	// destroy objects
	m_Mutex.Lock();
	for( uint_t i = 0; i < m_lstObjects.GetSize(); ++i )
	{
		delete m_lstObjects[i];
	}
	m_lstObjects.Clear();
	m_Mutex.Unlock();
}

void CScene::ProcessTick( float_t _fTime )
{
	// update objects
	m_Mutex.Lock();
	for( uint_t i = 0; i < m_lstObjects.GetSize(); ++i )
	{
		ABCObject *pObject = m_lstObjects[i];
		m_Mutex.Unlock();

		pObject->Update(_fTime);

		m_Mutex.Lock();
	}
	m_Mutex.Unlock();
}
